<template>
	<div class="page_user my_home" id="user_address">
		<div class="warp">
			<div class="container">
				<div class="row justify-content-between">
					<div class="col-12 col-md-3">
						<div class="card_menu">
							<!-- 左侧边栏 -->
							<list_admin_menu_user></list_admin_menu_user>
						</div>
					</div>
					<div class="col-12 col-md-9">
						<div class="card_addres pl-2">
							<div class="warp">
								<div class="container-fluid">
									<el-row>
										<div>欢迎来到个人中心</div>
									</el-row>
									<el-row>
														<el-col v-if="$check_figure('/fraud_knowledge/table')" :span="8">
											<div class="card chart">
																												<doughnutChart v-if="list_fraud_knowledge.length" id="list_fraud_knowledge" :list="list_fraud_knowledge" :title="'诈骗知识统计'"></doughnutChart>
												<div v-if="!list_fraud_knowledge.length">诈骗知识没有符合条件的数据</div>
																																																</div>
										</el-col>
															<el-col v-if="$check_figure('/community_communication/table')" :span="8">
											<div class="card chart">
																												<pieChart v-if="list_community_communication.length" id="list_community_communication" :list="list_community_communication" :title="'社区交流统计'"></pieChart>
												<div v-if="!list_community_communication.length">社区交流没有符合条件的数据</div>
																																																							</div>
										</el-col>
											</el-row>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import list_admin_menu_user from "@/components/diy/list_admin_menu_user.vue";
	import pieChart from "@/components/charts/pie_chart";
	import doughnutChart from "@/components/charts/doughnut_chart";
	export default {
		data() {
			return {
											list_fraud_knowledge: [],
												list_community_communication: [],
						};
		},
		mounted() {
		},
		methods: {
			async get_nickname(list,flag){
				if (flag) {
					for (let i=0;i<list.length;i++){
						await this.$get(
								"~/api/user/get_obj?user_id="+list[i],
								null,
								(json) => {
									if (json.result) {
										list[i] = json.result.obj.nickname;
									}
								});
					}
				}else {
					for (let i=0;i<list.length;i++){
						await this.$get(
								"~/api/user/get_obj?user_id="+list[i].name,
								null,
								(json) => {
									if (json.result) {
										list[i].name = json.result.obj.nickname;
									}
								});
					}
				}
			},
																				// 获取诈骗知识统计图数据
			get_list_fraud_knowledge() {
				let data = {};
								let flag = false;
												this.$get("~/api/fraud_knowledge/list_group?groupby=fraud_classification", data, (json) => {
					if (json.result) {
						var list = json.result.list;
						this.list_fraud_knowledge = list.map((o) => {
							return {
												name: o[1],
												value: o[0]
							};
						});
						if (flag){
							this.get_nickname(this.list_fraud_knowledge,false);
						}
					}
				});
			},
																																														// 获取社区交流统计图数据
			get_list_community_communication() {
				let data = {};
								let flag = false;
												let user_group = this.$store.state.user.user_group;
				let user_id = this.$store.state.user.user_id;
				if (user_group!='管理员'){
										let sqlwhere = "(";
																																																									if (user_group=="学生用户"){
						sqlwhere+= "student_users = " + user_id + " or ";
					}
																																																									if (sqlwhere.length>1){
						sqlwhere = sqlwhere.substr(0,sqlwhere.length-4);
						sqlwhere += ")";
						data.sqlwhere = sqlwhere;
					}
									}
								this.$get("~/api/community_communication/list_group?groupby=communication_classification", data, (json) => {
					if (json.result) {
						var list = json.result.list;
						this.list_community_communication = list.map((o) => {
							return {
												name: o[1],
												value: o[0]
							};
						});
						if (flag){
							this.get_nickname(this.list_community_communication,false);
						}
					}
				});
			},
																																			},
		created() {
			setTimeout(() => {
							// 执行诈骗知识数据获取
			this.get_list_fraud_knowledge();
								// 执行社区交流数据获取
			this.get_list_community_communication();
					}, 1000);
		},
		components: {
			pieChart,
			doughnutChart,
			list_admin_menu_user
		},
	};
</script>

<style scoped>
	.container {
		min-height: 800px;
	}
</style>
